<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const data = {
            'abCd': 1,
            'bcDe': [
                {
                    'cbEf': 1
                }
            ]
        }
        function dfs(data) {
            if (typeof data !== 'object' || !data) return data
            if (Array.isArray(data)) {
                return data.map((item) => dfs(item))
            }

            let newObj = {}
            for (let key in data) {
                let newKey = key.replace(/([A-Z])/g, (res) => {
                    return '_' + res.toLowerCase()
                })
                newObj[newKey] = dfs(data[key])
            }
            return newObj
        }
        const res = dfs(data)
        console.log(res);

    </script>
</body>

</html>